package com.chixing.controller;

import com.chixing.service.EvaluateService;
import com.chixing.service.HouseService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class HouseController {
    @Autowired
    private HouseService houseService;
    @Autowired
    private EvaluateService evaluateService;
    @GetMapping(value = {"houses/{id}","houses/{id}/page/{pageNum}"})
    public ModelAndView getById(@PathVariable("id") Integer id,
                                @PathVariable(value = "pageNum" ,required = false) Integer pageNum){
        if (pageNum==null)
            pageNum=1;
        ServerResponse serverResponse = houseService.getByName(id);
        ServerResponse evaluateServer = evaluateService.getByHoutlId(id,pageNum);
        ModelAndView mav = new ModelAndView();
        mav.addObject("serviceResponse", serverResponse);
        mav.addObject("evaluateServer",evaluateServer);
        mav.setViewName("houses/house1");
        return mav;
    }
}
